public class Test {
    public List<Integer> inorderTraversal(TreeNode root) {//非递归中序遍历
        List<Integer> ret=new ArrayList();
        if(root==null) return ret;
        Stack <TreeNode> stack=new Stack();
        TreeNode cur=root;
        while(cur!=null||!stack.isEmpty()){
            while(cur!=null){
                stack.push(cur);
                cur=cur.left;
            }
            TreeNode top=stack.pop();
            ret.add(top.val);
            if(top.right!=null){
                cur=top.right;
            }
        }
        return ret;
    }
}
